package com.cn.study.config;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author mjy
 * @date 2021/12/14
 * @description
 */
@Configuration
public class ProducerConfiguration {

    private Logger log = LoggerFactory.getLogger(ProducerConfiguration.class);

    @Autowired
    private ProducerConfig producerConfig;


    /**
     * 创建普通消费者发送实例
     */
    @Bean
    public DefaultMQProducer creatDefaultProducer() throws Exception{
        log.info("--------开始创建生产者----------");
        DefaultMQProducer producer = new DefaultMQProducer(producerConfig.getGroupName());
        producer.setNamesrvAddr(producerConfig.getNameServer());producer.setVipChannelEnabled(false);
        producer.setVipChannelEnabled(false);
        producer.setRetryTimesWhenSendAsyncFailed(10);
        producer.start();
        log.info("--------消息者创建成功 nameServer address={}----------"+producer.getNamesrvAddr());
        return producer;
    }



}
